/**
 * Copyright 2012 Roger Cockshutt
 * krakenbrau@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.parallelrl.process;

import com.googlecode.parallelrl.data.ecs.ECSManager;
import com.googlecode.parallelrl.util.Box2D;
import com.googlecode.parallelrl.util.Point2D;
import com.googlecode.parallelrl.util.Tree2D;

/**
 * @author Roger Cockshutt
 *
 */
public class ArenaGenerator implements ISpaceGenerator {

	/**
	 * 
	 */
	public ArenaGenerator() {
		
	}

	
	@Override
	public Tree2D generate(Object[] params) {
		Integer xSize = null;
		Integer ySize = null;
		if (params[0] instanceof Integer
				&& params[1] instanceof Integer) {
			xSize = (Integer) params[0];
			ySize = (Integer) params[1];
		} else {
			throw new IllegalArgumentException("Unexpected arguments: " + params.toString());
		}
		Box2D spaceBounds = new Box2D(ySize, xSize);
		Tree2D space = new Tree2D(spaceBounds);
		for (int y = 0; y < ySize; y++) {
			for (int x = 0; x < xSize; x++) {
				Point2D p = new Point2D(y, x);
				
				Long pID = space.getHashForPoint(p);
				ECSManager.createEntity(pID);
				if (y == 0
						|| x == 0
						|| y == ySize - 1
						|| x == xSize - 1) {
					ECSManager.setComponent(pID, "Occupants", ECSManager.createEntityFromAssemblage("WALL").toString());
				} else {
					ECSManager.setComponent(pID, "Occupants", ECSManager.createEntityFromAssemblage("FLOOR").toString());
				}
			}
		}
		
		return null;
	}

}
